/*	Copyright (c) 2010 MIEM (http://miem.edu.ru/)
 *
 *	Authors:
 *		* Andrey Shtykovskiy    ( ashty@itas.miem.edu.ru      )
 *		* Edward Klyshinsky     ( klyshinsky@itas.miem.edu.ru )
 *		* Sergey R. Tumkovsky   ( srt@itas.miem.edu.ru        )
 *
 *	This file is part of MOAN (morphology analysis) software.
 *
 *	MOAN is free software: you can redistribute it and/or modify it 
 *	under the terms of the GNU General Public License as published 
 *	by the Free Software Foundation, either version 3 of the License, 
 *	or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License 
 *	along with MOAN. If not, see http://www.gnu.org/licenses/.
 */

#ifndef __PARAMETER_UNITTEST_HPP_GUARD__
#define __PARAMETER_UNITTEST_HPP_GUARD__

#include <stdint.h>
#include <vector>

#include "..\..\thirdparty\gtest\gtest.h"

#include "..\..\src\moan\parameter.hpp"


TEST( parameter_constructor,  create_from_value ) {
	moan::parameter *p;
	moan::parameter::value_type v = 0;

	p = new moan::parameter(110);
	v = p->get().value();

	delete p;
	p = NULL;

	ASSERT_EQ(110,  v);
}

class parameter_basic_test : public ::testing::Test {

protected:
	typedef moan::parameter container_type;

	virtual void SetUp() {
		p1 = new container_type();
		p2 = new container_type();
	}

	virtual void TearDown() {
		delete p1;
		p1 = NULL;

		delete p2;
		p2 = NULL;
	}

	container_type *p1, *p2;
};

TEST_F( parameter_basic_test, on_create ) {
	ASSERT_EQ( 0, p1->get().value() );
	ASSERT_EQ( 0, p2->get().value() );
	ASSERT_EQ( 63, p1->get().cap() );
	ASSERT_EQ( 63, p2->get().cap() );
}

TEST_F( parameter_basic_test, compare_in_full ) {

	p1->value().set(10);
	p2->value().set(10);

	ASSERT_EQ( 1024, p1->get().value() );
	ASSERT_EQ( 1024, p2->get().value() );

	ASSERT_TRUE( *p1 == *p2 );
}

TEST_F( parameter_basic_test, compare_single ) {
	
	p1->value().set(10);
	p2->value().set(10);

	ASSERT_TRUE( p1->equals( *p2, 10 ) );

	p1->value().set(11);

	ASSERT_FALSE( p1->equals( *p2, 11 ) );
}

TEST_F( parameter_basic_test, compare_range ) {
	
	p1->value().set(10);
	p1->value().set(12);
	p2->value().set(10);
	p2->value().set(12);

	ASSERT_TRUE( p1->equals( *p2, 10, 12 ) );
}

TEST_F( parameter_basic_test, compare_set ) {

	p1->value().set(10);
	p1->value().set(11);
	p2->value().set(10);
	p2->value().set(11);

	std::vector<size_t> v (10, 11);

	ASSERT_TRUE( p1->equals( *p2, v.begin(), v.end() ) );

	v.push_back(9);
	p1->value().set(9);

	ASSERT_FALSE( p1->equals( *p2, v.begin(), v.end() ) );
}

#endif /* __PARAMETER_UNITTEST_HPP_GUARD__ */